package chixing.day15.work;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class Car {
    Map<String,Integer> map = new HashMap<>();
    List<String> list = new ArrayList<>();
    public void add(String carName,Integer carsale) {
        map.put(carName,carsale);
    }
    public void display() {
        for (Map.Entry<String,Integer> entry : map.entrySet()) {
            System.out.println(entry.getKey() + ":" + entry.getValue());
        }
    }
    public void size() {
        System.out.println(map.size());
    }
    public Map<String,Integer> find(String carName) {
        if (map.containsKey(carName)) {
            Map<String,Integer> map1 = new HashMap<>();
            map1.put(carName,map.get(carName));
            return map1;
        } else {
            return null;
        }
    }
    public Map.Entry<String, Integer> findHighSale() {
        Map.Entry<String, Integer> maxEntry = null;
        for (Map.Entry<String, Integer> entry : map.entrySet()) {
            if (maxEntry == null || entry.getValue() > maxEntry.getValue()) {
                maxEntry = entry;
            }
        }
        return maxEntry;
    }
    public List<String> findLimitSale() {
        for (Map.Entry<String, Integer> entry : map.entrySet()) {
            if ( entry.getValue()<300) {
                list.add(entry.getKey());
            }
        }
        return list;
    }
    public static void main(String[] args) {
        Car car = new Car();
        car.add("Audi", 100);
        car.add("BMW", 200);
        car.add("Benz", 300);
        car.add("特斯拉", 400);
        car.add("Ferrari", 500);
        car.size();
        Map<String, Integer> tesila = car.find("特斯拉");
        System.out.println(tesila);
        Map.Entry<String, Integer> highSale = car.findHighSale();
        System.out.println(highSale);
        List<String> limitSale = car.findLimitSale();
        System.out.println(limitSale);
    }

}
